﻿using Appliaction.Dto.Inv;
using Appliaction.IAppServices.Inv;
using AutoMapper;
using Domain.Entitys.Inv;
using Domain.IRepositorys.Inv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Inv
{
    public class Inv_SampServices:IInv_SampServices
    {
        private readonly IInv_SampRepository  inv_SampRepository;

        private readonly IMapper mapper;

        public Inv_SampServices(IInv_SampRepository inv_SampRepository, IMapper mapper)
        {
            this.inv_SampRepository = inv_SampRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 删除抽检单
        /// </summary>
        /// <param name="Samp_id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_Qty_Delete(int Samp_id)
        {
            return inv_SampRepository.Inv_Qty_Delete(Samp_id);
        }

        /// <summary>
        /// 根据编号查询主表
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<Inv_samp>> Inv_Qty_SelectCode(string Samp_code)
        {
           return inv_SampRepository.Inv_Qty_SelectCode(Samp_code);
        }
        /// <summary>
        /// 根据编号查询明细表
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<List<Inv_prodInfo>> Inv_Qty_SelectDetail(string Samp_code)
        {
            return inv_SampRepository.Inv_Qty_SelectDetail(Samp_code);
        }
        /// <summary>
        /// 修改审核状态
        /// </summary>
        /// <param name="inv_SampUpdateDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_samp_audit_statusUpdate(Inv_SampUpdateDto inv_SampUpdateDto)
        {
           Inv_samp inv_samp = mapper.Map<Inv_samp>(inv_SampUpdateDto);
            return inv_SampRepository.Inv_samp_audit_statusUpdate(inv_samp);
        }
        /// <summary>
        /// 查询数量
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <param name="Samp_type"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_Samp_selectCount(string Samp_code, string Samp_type)
        {
            return inv_SampRepository.Inv_Samp_selectCount(Samp_code, Samp_type);
        }
        /// <summary>
        /// 查询分页
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <param name="Samp_type"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public List<Samp_SelectDto> Inv_Samp_selectFY(string Samp_code, string Samp_type, int currentPage, int pageSize)
        {
            return mapper.Map<List<Samp_SelectDto>>(inv_SampRepository.Inv_Samp_selectFY(Samp_code, Samp_type, currentPage, pageSize));
        }

        /// <summary>
        /// 添加抽检单
        /// </summary>
        /// <param name="inv_SampAddDto"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
       
        public Task<int> Inv_Samp_Insert(Inv_SampAddDto inv_SampAddDto)
        {
            Inv_samp inv_Samp= mapper.Map<Inv_samp>(inv_SampAddDto);
            return inv_SampRepository.Inv_Samp_Insert(inv_Samp);
        }
        /// <summary>
        /// 添加抽检单详情
        /// </summary>
        /// <param name="inv_prodInfo"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Inv_prodInfo_Insert(List<Inv_ProdInfoAddDto> inv_prodInfoDto)
        {
            var inv_prodInfos = inv_prodInfoDto.Select(dto => new Inv_prodInfo
            {
                Samp_id=dto.Samp_id,
                Pro_name=dto.Pro_name,
                Pro_code=dto.Pro_code,
                Pro_brand=dto.Pro_brand,
                Pro_model=dto.Pro_model,
                Unitmeas_id=dto.Unitmeas_id,
                Samp_numder=dto.Samp_numder,
                ProdInfo_totnum_qify=dto.ProdInfo_totnum_qify,
                ProdInfo_totnum_uqual=dto.ProdInfo_totnum_uqual,
                ProdInfo_Sampling_results=dto.ProdInfo_Sampling_results,
                Warehouse_code=dto.Warehouse_code,
                stock_entry_no=dto.stock_entry_no

            }).ToList();
            return await inv_SampRepository.Inv_prodInfo_Insert(inv_prodInfos);
        }
        /// <summary>
        /// 编号查询ID
        /// </summary>
        /// <param name="Samp_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_sampt_selectId(string Samp_code)
        {
            return inv_SampRepository.Inv_sampt_selectId(Samp_code);
        }
        /// <summary>
        /// 修改抽检单
        /// </summary>
        /// <param name="inv_SampUpdateMerage"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<int> Inv_Smap_Update(Inv_SampUpdateMerage inv_SampUpdateMerage)
        {
           Inv_samp inv_Samp = mapper.Map<Inv_samp>(inv_SampUpdateMerage.inv_SmapUpdateMainDto);
           return inv_SampRepository.Inv_Smap_Update(inv_Samp, inv_SampUpdateMerage.inv_ProdInfos);
        }


        /// <summary>
        /// 查询抽检单--出库单--查询
        /// </summary>
        /// <param name="code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<Inv_samp> Inv_Select_SampSelect(string code, int currentPage, int pageSize) { 
        
         return inv_SampRepository.Inv_Select_SampSelect(code,currentPage,pageSize);
        }

        /// <summary>
        /// 查询抽检单--出库单--查询
        /// </summary>
        /// <returns></returns>
        public Task<int> Inv_Select_SmapSelect_Count(string code) { 
        
        return inv_SampRepository.Inv_Select_SmapSelect_Count(code);
        }


        /// <summary>
        /// 查询抽检单--出库单--查询详情
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public List<Inv_prodInfo> Inv_Select_Inv_prodInfo(string code) { 
        
        return inv_SampRepository.Inv_Select_Inv_prodInfo(code);
        }


        /// <summary>
        /// 出库完成之后,审核完毕--修改抽检单的字段
        /// </summary>
        /// <returns></returns>
        public Task<int> Inv_Samp_Outbound_update(int id) { 
        
        return inv_SampRepository.Inv_Samp_Outbound_update(id);
        }
    }
}
